/**
 *
 */
import Util;
import OSS;
import RPC;
import OpenPlatform;
import OSSUtil;
import FileForm;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('dplus', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model AePredictCategoryRequest {
  picUrl?: string(name='PicUrl'),
}

model AePredictCategoryAdvanceRequest {
  picUrlObject: readable(name='PicUrlObject'),
}

model AePredictCategoryResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: object(name='body'),
}

async function aePredictCategoryWithOptions(request: AePredictCategoryRequest, runtime: Util.RuntimeOptions): AePredictCategoryResponse {
  Util.validateModel(request);
  var body : map[string]any= {};
  if (!Util.isUnset(request.picUrl)) {
    body['PicUrl'] = request.picUrl;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'AePredictCategory',
    version = '2020-12-16',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function aePredictCategory(request: AePredictCategoryRequest): AePredictCategoryResponse {
  var runtime = new Util.RuntimeOptions{};
  return aePredictCategoryWithOptions(request, runtime);
}

async function aePredictCategoryAdvance(request: AePredictCategoryAdvanceRequest, runtime: Util.RuntimeOptions): AePredictCategoryResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.isUnset(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new RPC.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'dplus',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = null;

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var aePredictCategoryReq = new AePredictCategoryRequest{};
  OpenApiUtil.convert(request, aePredictCategoryReq);

  if(!Util.isUnset(request.picUrlObject)){
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.endpoint, authResponse.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.objectKey,
      content = request.picUrlObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.accessKeyId,
      policy = authResponse.encodedPolicy,
      signature = authResponse.signature,
      key = authResponse.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    aePredictCategoryReq.picUrl =   `http://${authResponse.bucket}.${authResponse.endpoint}/${authResponse.objectKey}`;
  }
  var aePredictCategoryResp = aePredictCategoryWithOptions(aePredictCategoryReq, runtime);
  return aePredictCategoryResp;
}

model AePropRecRequest {
  picUrl?: string(name='PicUrl'),
}

model AePropRecAdvanceRequest {
  picUrlObject: readable(name='PicUrlObject'),
}

model AePropRecResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: object(name='body'),
}

async function aePropRecWithOptions(request: AePropRecRequest, runtime: Util.RuntimeOptions): AePropRecResponse {
  Util.validateModel(request);
  var body : map[string]any= {};
  if (!Util.isUnset(request.picUrl)) {
    body['PicUrl'] = request.picUrl;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'AePropRec',
    version = '2020-12-16',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function aePropRec(request: AePropRecRequest): AePropRecResponse {
  var runtime = new Util.RuntimeOptions{};
  return aePropRecWithOptions(request, runtime);
}

async function aePropRecAdvance(request: AePropRecAdvanceRequest, runtime: Util.RuntimeOptions): AePropRecResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.isUnset(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new RPC.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'dplus',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = null;

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var aePropRecReq = new AePropRecRequest{};
  OpenApiUtil.convert(request, aePropRecReq);

  if(!Util.isUnset(request.picUrlObject)){
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.endpoint, authResponse.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.objectKey,
      content = request.picUrlObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.accessKeyId,
      policy = authResponse.encodedPolicy,
      signature = authResponse.signature,
      key = authResponse.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    aePropRecReq.picUrl =   `http://${authResponse.bucket}.${authResponse.endpoint}/${authResponse.objectKey}`;
  }
  var aePropRecResp = aePropRecWithOptions(aePropRecReq, runtime);
  return aePropRecResp;
}

model AlivisionImgdupRequest {
  imageHeight?: int32(name='ImageHeight'),
  imageWidth?: int32(name='ImageWidth'),
  outputImageNum?: int32(name='OutputImageNum'),
  picNumList?: string(name='PicNumList'),
  picUrlList?: string(name='PicUrlList'),
}

model AlivisionImgdupResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: object(name='body'),
}

async function alivisionImgdupWithOptions(request: AlivisionImgdupRequest, runtime: Util.RuntimeOptions): AlivisionImgdupResponse {
  Util.validateModel(request);
  var body : map[string]any= {};
  if (!Util.isUnset(request.imageHeight)) {
    body['ImageHeight'] = request.imageHeight;
  }
  if (!Util.isUnset(request.imageWidth)) {
    body['ImageWidth'] = request.imageWidth;
  }
  if (!Util.isUnset(request.outputImageNum)) {
    body['OutputImageNum'] = request.outputImageNum;
  }
  if (!Util.isUnset(request.picNumList)) {
    body['PicNumList'] = request.picNumList;
  }
  if (!Util.isUnset(request.picUrlList)) {
    body['PicUrlList'] = request.picUrlList;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'AlivisionImgdup',
    version = '2020-12-16',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function alivisionImgdup(request: AlivisionImgdupRequest): AlivisionImgdupResponse {
  var runtime = new Util.RuntimeOptions{};
  return alivisionImgdupWithOptions(request, runtime);
}

model CreateImageAmazonTaskRequest {
  gif?: boolean(name='Gif'),
  imgUrlList?: [ string ](name='ImgUrlList'),
  templateMode?: string(name='TemplateMode'),
  textList?: [ string ](name='TextList'),
}

model CreateImageAmazonTaskShrinkRequest {
  gif?: boolean(name='Gif'),
  imgUrlListShrink?: string(name='ImgUrlList'),
  templateMode?: string(name='TemplateMode'),
  textListShrink?: string(name='TextList'),
}

model CreateImageAmazonTaskResponseBody = {
  code?: long(name='Code'),
  data?: long(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId', description='Id of the request'),
  successResponse?: boolean(name='SuccessResponse'),
}

model CreateImageAmazonTaskResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: CreateImageAmazonTaskResponseBody(name='body'),
}

async function createImageAmazonTaskWithOptions(tmpReq: CreateImageAmazonTaskRequest, runtime: Util.RuntimeOptions): CreateImageAmazonTaskResponse {
  Util.validateModel(tmpReq);
  var request = new CreateImageAmazonTaskShrinkRequest{};
  OpenApiUtil.convert(tmpReq, request);
  if (!Util.isUnset(tmpReq.imgUrlList)) {
    request.imgUrlListShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.imgUrlList, 'ImgUrlList', 'json');
  }
  if (!Util.isUnset(tmpReq.textList)) {
    request.textListShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.textList, 'TextList', 'json');
  }
  var query = {};
  if (!Util.isUnset(request.gif)) {
    query['Gif'] = request.gif;
  }
  if (!Util.isUnset(request.imgUrlListShrink)) {
    query['ImgUrlList'] = request.imgUrlListShrink;
  }
  if (!Util.isUnset(request.templateMode)) {
    query['TemplateMode'] = request.templateMode;
  }
  if (!Util.isUnset(request.textListShrink)) {
    query['TextList'] = request.textListShrink;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'CreateImageAmazonTask',
    version = '2020-12-16',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function createImageAmazonTask(request: CreateImageAmazonTaskRequest): CreateImageAmazonTaskResponse {
  var runtime = new Util.RuntimeOptions{};
  return createImageAmazonTaskWithOptions(request, runtime);
}

model CreateRemoveWorkTaskRequest {
  itemIdentity?: string(name='ItemIdentity'),
  picUrl?: string(name='PicUrl'),
}

model CreateRemoveWorkTaskAdvanceRequest {
  picUrlObject: readable(name='PicUrlObject'),
  itemIdentity?: string(name='ItemIdentity'),
}

model CreateRemoveWorkTaskResponseBody = {
  code?: long(name='Code'),
  data?: long(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId', description='Id of the request'),
  successResponse?: boolean(name='SuccessResponse'),
}

model CreateRemoveWorkTaskResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: CreateRemoveWorkTaskResponseBody(name='body'),
}

async function createRemoveWorkTaskWithOptions(request: CreateRemoveWorkTaskRequest, runtime: Util.RuntimeOptions): CreateRemoveWorkTaskResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.itemIdentity)) {
    query['ItemIdentity'] = request.itemIdentity;
  }
  if (!Util.isUnset(request.picUrl)) {
    query['PicUrl'] = request.picUrl;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'CreateRemoveWorkTask',
    version = '2020-12-16',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function createRemoveWorkTask(request: CreateRemoveWorkTaskRequest): CreateRemoveWorkTaskResponse {
  var runtime = new Util.RuntimeOptions{};
  return createRemoveWorkTaskWithOptions(request, runtime);
}

async function createRemoveWorkTaskAdvance(request: CreateRemoveWorkTaskAdvanceRequest, runtime: Util.RuntimeOptions): CreateRemoveWorkTaskResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.isUnset(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new RPC.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'dplus',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = null;

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var createRemoveWorkTaskReq = new CreateRemoveWorkTaskRequest{};
  OpenApiUtil.convert(request, createRemoveWorkTaskReq);

  if(!Util.isUnset(request.picUrlObject)){
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.endpoint, authResponse.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.objectKey,
      content = request.picUrlObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.accessKeyId,
      policy = authResponse.encodedPolicy,
      signature = authResponse.signature,
      key = authResponse.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    createRemoveWorkTaskReq.picUrl =   `http://${authResponse.bucket}.${authResponse.endpoint}/${authResponse.objectKey}`;
  }
  var createRemoveWorkTaskResp = createRemoveWorkTaskWithOptions(createRemoveWorkTaskReq, runtime);
  return createRemoveWorkTaskResp;
}

model FaceshifterTRequest {
  age?: int32(name='Age'),
  gender?: int32(name='Gender'),
  picUrl?: string(name='PicUrl'),
  race?: int32(name='Race'),
}

model FaceshifterTAdvanceRequest {
  picUrlObject: readable(name='PicUrlObject'),
  age?: int32(name='Age'),
  gender?: int32(name='Gender'),
  race?: int32(name='Race'),
}

model FaceshifterTResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: object(name='body'),
}

async function faceshifterTWithOptions(request: FaceshifterTRequest, runtime: Util.RuntimeOptions): FaceshifterTResponse {
  Util.validateModel(request);
  var body : map[string]any= {};
  if (!Util.isUnset(request.age)) {
    body['Age'] = request.age;
  }
  if (!Util.isUnset(request.gender)) {
    body['Gender'] = request.gender;
  }
  if (!Util.isUnset(request.picUrl)) {
    body['PicUrl'] = request.picUrl;
  }
  if (!Util.isUnset(request.race)) {
    body['Race'] = request.race;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'FaceshifterT',
    version = '2020-12-16',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function faceshifterT(request: FaceshifterTRequest): FaceshifterTResponse {
  var runtime = new Util.RuntimeOptions{};
  return faceshifterTWithOptions(request, runtime);
}

async function faceshifterTAdvance(request: FaceshifterTAdvanceRequest, runtime: Util.RuntimeOptions): FaceshifterTResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.isUnset(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new RPC.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'dplus',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = null;

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var faceshifterTReq = new FaceshifterTRequest{};
  OpenApiUtil.convert(request, faceshifterTReq);

  if(!Util.isUnset(request.picUrlObject)){
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.endpoint, authResponse.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.objectKey,
      content = request.picUrlObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.accessKeyId,
      policy = authResponse.encodedPolicy,
      signature = authResponse.signature,
      key = authResponse.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    faceshifterTReq.picUrl =   `http://${authResponse.bucket}.${authResponse.endpoint}/${authResponse.objectKey}`;
  }
  var faceshifterTResp = faceshifterTWithOptions(faceshifterTReq, runtime);
  return faceshifterTResp;
}

model GetTaskResultRequest {
  taskId?: long(name='TaskId'),
}

model GetTaskResultResponseBody = {
  code?: long(name='Code'),
  data?: {
    result?: string(name='Result'),
    status?: long(name='Status'),
    statusName?: string(name='StatusName'),
    taskId?: long(name='TaskId'),
  }(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId', description='Id of the request'),
  successResponse?: boolean(name='SuccessResponse'),
}

model GetTaskResultResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: GetTaskResultResponseBody(name='body'),
}

async function getTaskResultWithOptions(request: GetTaskResultRequest, runtime: Util.RuntimeOptions): GetTaskResultResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.taskId)) {
    query['TaskId'] = request.taskId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GetTaskResult',
    version = '2020-12-16',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function getTaskResult(request: GetTaskResultRequest): GetTaskResultResponse {
  var runtime = new Util.RuntimeOptions{};
  return getTaskResultWithOptions(request, runtime);
}

model GetTaskStatusRequest {
  taskId?: long(name='TaskId'),
}

model GetTaskStatusResponseBody = {
  code?: long(name='Code'),
  data?: {
    status?: long(name='Status'),
    statusName?: string(name='StatusName'),
    taskId?: long(name='TaskId'),
  }(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId', description='Id of the request'),
  successResponse?: boolean(name='SuccessResponse'),
}

model GetTaskStatusResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: GetTaskStatusResponseBody(name='body'),
}

async function getTaskStatusWithOptions(request: GetTaskStatusRequest, runtime: Util.RuntimeOptions): GetTaskStatusResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.taskId)) {
    query['TaskId'] = request.taskId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GetTaskStatus',
    version = '2020-12-16',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function getTaskStatus(request: GetTaskStatusRequest): GetTaskStatusResponse {
  var runtime = new Util.RuntimeOptions{};
  return getTaskStatusWithOptions(request, runtime);
}

model KuajingSegRequest {
  picUrl?: string(name='PicUrl'),
  returnPicFormat?: string(name='ReturnPicFormat'),
  returnPicType?: string(name='ReturnPicType'),
}

model KuajingSegAdvanceRequest {
  picUrlObject: readable(name='PicUrlObject'),
  returnPicFormat?: string(name='ReturnPicFormat'),
  returnPicType?: string(name='ReturnPicType'),
}

model KuajingSegResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: object(name='body'),
}

async function kuajingSegWithOptions(request: KuajingSegRequest, runtime: Util.RuntimeOptions): KuajingSegResponse {
  Util.validateModel(request);
  var body : map[string]any= {};
  if (!Util.isUnset(request.picUrl)) {
    body['PicUrl'] = request.picUrl;
  }
  if (!Util.isUnset(request.returnPicFormat)) {
    body['ReturnPicFormat'] = request.returnPicFormat;
  }
  if (!Util.isUnset(request.returnPicType)) {
    body['ReturnPicType'] = request.returnPicType;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'KuajingSeg',
    version = '2020-12-16',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function kuajingSeg(request: KuajingSegRequest): KuajingSegResponse {
  var runtime = new Util.RuntimeOptions{};
  return kuajingSegWithOptions(request, runtime);
}

async function kuajingSegAdvance(request: KuajingSegAdvanceRequest, runtime: Util.RuntimeOptions): KuajingSegResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.isUnset(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new RPC.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'dplus',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = null;

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var kuajingSegReq = new KuajingSegRequest{};
  OpenApiUtil.convert(request, kuajingSegReq);

  if(!Util.isUnset(request.picUrlObject)){
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.endpoint, authResponse.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.objectKey,
      content = request.picUrlObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.accessKeyId,
      policy = authResponse.encodedPolicy,
      signature = authResponse.signature,
      key = authResponse.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    kuajingSegReq.picUrl =   `http://${authResponse.bucket}.${authResponse.endpoint}/${authResponse.objectKey}`;
  }
  var kuajingSegResp = kuajingSegWithOptions(kuajingSegReq, runtime);
  return kuajingSegResp;
}

model RemoveWordsRequest {
  picUrl?: string(name='PicUrl'),
}

model RemoveWordsAdvanceRequest {
  picUrlObject: readable(name='PicUrlObject'),
}

model RemoveWordsResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: object(name='body'),
}

async function removeWordsWithOptions(request: RemoveWordsRequest, runtime: Util.RuntimeOptions): RemoveWordsResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.picUrl)) {
    query['PicUrl'] = request.picUrl;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'RemoveWords',
    version = '2020-12-16',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function removeWords(request: RemoveWordsRequest): RemoveWordsResponse {
  var runtime = new Util.RuntimeOptions{};
  return removeWordsWithOptions(request, runtime);
}

async function removeWordsAdvance(request: RemoveWordsAdvanceRequest, runtime: Util.RuntimeOptions): RemoveWordsResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.isUnset(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new RPC.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'dplus',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = null;

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var removeWordsReq = new RemoveWordsRequest{};
  OpenApiUtil.convert(request, removeWordsReq);

  if(!Util.isUnset(request.picUrlObject)){
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.endpoint, authResponse.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.objectKey,
      content = request.picUrlObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.accessKeyId,
      policy = authResponse.encodedPolicy,
      signature = authResponse.signature,
      key = authResponse.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    removeWordsReq.picUrl =   `http://${authResponse.bucket}.${authResponse.endpoint}/${authResponse.objectKey}`;
  }
  var removeWordsResp = removeWordsWithOptions(removeWordsReq, runtime);
  return removeWordsResp;
}

model ReplaceBackgroundRequest {
  backgroundId?: string(name='BackgroundId', description='返回的图片背景图片ID'),
  num?: int32(name='Num'),
  picBackgroundUrl?: string(name='PicBackgroundUrl'),
  picUrl?: string(name='PicUrl', description='图片地址'),
}

model ReplaceBackgroundAdvanceRequest {
  picUrlObject: readable(name='PicUrlObject'),
  backgroundId?: string(name='BackgroundId', description='返回的图片背景图片ID'),
  num?: int32(name='Num'),
  picBackgroundUrl?: string(name='PicBackgroundUrl'),
}

model ReplaceBackgroundResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: object(name='body'),
}

async function replaceBackgroundWithOptions(request: ReplaceBackgroundRequest, runtime: Util.RuntimeOptions): ReplaceBackgroundResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.backgroundId)) {
    query['BackgroundId'] = request.backgroundId;
  }
  if (!Util.isUnset(request.num)) {
    query['Num'] = request.num;
  }
  if (!Util.isUnset(request.picBackgroundUrl)) {
    query['PicBackgroundUrl'] = request.picBackgroundUrl;
  }
  if (!Util.isUnset(request.picUrl)) {
    query['PicUrl'] = request.picUrl;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'ReplaceBackground',
    version = '2020-12-16',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function replaceBackground(request: ReplaceBackgroundRequest): ReplaceBackgroundResponse {
  var runtime = new Util.RuntimeOptions{};
  return replaceBackgroundWithOptions(request, runtime);
}

async function replaceBackgroundAdvance(request: ReplaceBackgroundAdvanceRequest, runtime: Util.RuntimeOptions): ReplaceBackgroundResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.isUnset(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new RPC.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'dplus',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = null;

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var replaceBackgroundReq = new ReplaceBackgroundRequest{};
  OpenApiUtil.convert(request, replaceBackgroundReq);

  if(!Util.isUnset(request.picUrlObject)){
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.endpoint, authResponse.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.objectKey,
      content = request.picUrlObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.accessKeyId,
      policy = authResponse.encodedPolicy,
      signature = authResponse.signature,
      key = authResponse.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    replaceBackgroundReq.picUrl =   `http://${authResponse.bucket}.${authResponse.endpoint}/${authResponse.objectKey}`;
  }
  var replaceBackgroundResp = replaceBackgroundWithOptions(replaceBackgroundReq, runtime);
  return replaceBackgroundResp;
}

model SeleteCommodityRequest {
  num?: int32(name='Num'),
  pid?: string(name='Pid'),
  query?: string(name='Query'),
  start?: int32(name='Start'),
}

model SeleteCommodityResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: object(name='body'),
}

async function seleteCommodityWithOptions(request: SeleteCommodityRequest, runtime: Util.RuntimeOptions): SeleteCommodityResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.num)) {
    query['Num'] = request.num;
  }
  if (!Util.isUnset(request.pid)) {
    query['Pid'] = request.pid;
  }
  if (!Util.isUnset(request.query)) {
    query['Query'] = request.query;
  }
  if (!Util.isUnset(request.start)) {
    query['Start'] = request.start;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'SeleteCommodity',
    version = '2020-12-16',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function seleteCommodity(request: SeleteCommodityRequest): SeleteCommodityResponse {
  var runtime = new Util.RuntimeOptions{};
  return seleteCommodityWithOptions(request, runtime);
}

model SeleteCommodityByBToBRequest {
  num?: int32(name='Num'),
  pid?: string(name='Pid'),
  query?: string(name='Query'),
  start?: int32(name='Start'),
}

model SeleteCommodityByBToBResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: object(name='body'),
}

async function seleteCommodityByBToBWithOptions(request: SeleteCommodityByBToBRequest, runtime: Util.RuntimeOptions): SeleteCommodityByBToBResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.num)) {
    query['Num'] = request.num;
  }
  if (!Util.isUnset(request.pid)) {
    query['Pid'] = request.pid;
  }
  if (!Util.isUnset(request.query)) {
    query['Query'] = request.query;
  }
  if (!Util.isUnset(request.start)) {
    query['Start'] = request.start;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'SeleteCommodityByBToB',
    version = '2020-12-16',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function seleteCommodityByBToB(request: SeleteCommodityByBToBRequest): SeleteCommodityByBToBResponse {
  var runtime = new Util.RuntimeOptions{};
  return seleteCommodityByBToBWithOptions(request, runtime);
}

model TbPredictCategoryRequest {
  picUrl?: string(name='PicUrl'),
}

model TbPredictCategoryAdvanceRequest {
  picUrlObject: readable(name='PicUrlObject'),
}

model TbPredictCategoryResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: object(name='body'),
}

async function tbPredictCategoryWithOptions(request: TbPredictCategoryRequest, runtime: Util.RuntimeOptions): TbPredictCategoryResponse {
  Util.validateModel(request);
  var body : map[string]any= {};
  if (!Util.isUnset(request.picUrl)) {
    body['PicUrl'] = request.picUrl;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'TbPredictCategory',
    version = '2020-12-16',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function tbPredictCategory(request: TbPredictCategoryRequest): TbPredictCategoryResponse {
  var runtime = new Util.RuntimeOptions{};
  return tbPredictCategoryWithOptions(request, runtime);
}

async function tbPredictCategoryAdvance(request: TbPredictCategoryAdvanceRequest, runtime: Util.RuntimeOptions): TbPredictCategoryResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.isUnset(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new RPC.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'dplus',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = null;

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var tbPredictCategoryReq = new TbPredictCategoryRequest{};
  OpenApiUtil.convert(request, tbPredictCategoryReq);

  if(!Util.isUnset(request.picUrlObject)){
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.endpoint, authResponse.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.objectKey,
      content = request.picUrlObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.accessKeyId,
      policy = authResponse.encodedPolicy,
      signature = authResponse.signature,
      key = authResponse.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    tbPredictCategoryReq.picUrl =   `http://${authResponse.bucket}.${authResponse.endpoint}/${authResponse.objectKey}`;
  }
  var tbPredictCategoryResp = tbPredictCategoryWithOptions(tbPredictCategoryReq, runtime);
  return tbPredictCategoryResp;
}

model TbPropRecRequest {
  picUrl?: string(name='PicUrl'),
}

model TbPropRecAdvanceRequest {
  picUrlObject: readable(name='PicUrlObject'),
}

model TbPropRecResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: object(name='body'),
}

async function tbPropRecWithOptions(request: TbPropRecRequest, runtime: Util.RuntimeOptions): TbPropRecResponse {
  Util.validateModel(request);
  var body : map[string]any= {};
  if (!Util.isUnset(request.picUrl)) {
    body['PicUrl'] = request.picUrl;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'TbPropRec',
    version = '2020-12-16',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function tbPropRec(request: TbPropRecRequest): TbPropRecResponse {
  var runtime = new Util.RuntimeOptions{};
  return tbPropRecWithOptions(request, runtime);
}

async function tbPropRecAdvance(request: TbPropRecAdvanceRequest, runtime: Util.RuntimeOptions): TbPropRecResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.isUnset(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new RPC.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'dplus',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = null;

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var tbPropRecReq = new TbPropRecRequest{};
  OpenApiUtil.convert(request, tbPropRecReq);

  if(!Util.isUnset(request.picUrlObject)){
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.endpoint, authResponse.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.objectKey,
      content = request.picUrlObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.accessKeyId,
      policy = authResponse.encodedPolicy,
      signature = authResponse.signature,
      key = authResponse.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    tbPropRecReq.picUrl =   `http://${authResponse.bucket}.${authResponse.endpoint}/${authResponse.objectKey}`;
  }
  var tbPropRecResp = tbPropRecWithOptions(tbPropRecReq, runtime);
  return tbPropRecResp;
}

model TransferUrlByBtoBRequest {
  offerId?: long(name='OfferId'),
  pid?: string(name='Pid'),
}

model TransferUrlByBtoBResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: object(name='body'),
}

async function transferUrlByBtoBWithOptions(request: TransferUrlByBtoBRequest, runtime: Util.RuntimeOptions): TransferUrlByBtoBResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.offerId)) {
    query['OfferId'] = request.offerId;
  }
  if (!Util.isUnset(request.pid)) {
    query['Pid'] = request.pid;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'TransferUrlByBtoB',
    version = '2020-12-16',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function transferUrlByBtoB(request: TransferUrlByBtoBRequest): TransferUrlByBtoBResponse {
  var runtime = new Util.RuntimeOptions{};
  return transferUrlByBtoBWithOptions(request, runtime);
}

